﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace work19
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }


        //登入按钮
        private void button1_Click(object sender, EventArgs e)
        {
            var uid = textBox1.Text;
            var psd = textBox2.Text;
            if (uid != "" && psd != "")
            {
                using (SqlConnection conn = new SqlConnection(DbHelper.connStr))
                {
                    conn.Open();

                    string sql = string.Format("select count(*) from Login Where admin='{0}' and password='{1}'", uid, psd);

                    SqlCommand cmd = new SqlCommand(sql, conn);

                    int result = (int)cmd.ExecuteScalar();

                    if (result > 0)
                    {
                        MessageBox.Show("登入成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        MainForm mainForm = new MainForm();
                        this.Hide();
                        mainForm.Show();
                    }
                    else
                    {
                        MessageBox.Show("登入失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }

                }
            }
            else
            {
                MessageBox.Show("你可能忘了还有啥没填！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
